<template>
	<view class="full-page" v-if="totalPage">
		
	</view>
	<view class="fast-box" v-else>
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="快速填写" titleStyle="{'color': '#000'}">
			
		</u-navbar>
		<view class="fast-item" v-for="(item,index) in list" :key="index" @tap="select(item.id)">
			<view class="display-flex just-between">
				<text>{{item.top_title}}</text>
				<text class="edit" @click.stop="$go('/showcase/showcase/addFastFill?id='+item.id)">编辑</text>
			</view>
			<view class="desc">
				{{item.type == 2 ? item.zz_taxpayer : item.qy_taxpayer}}
			</view>
		</view>
		
		<view class="empytView" v-if="list.length<=0">
			<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
		</view>
		
		<view class="subbox" >
			<text @click="$go('/showcase/showcase/addFastFill')">新增发票信息</text>
		</view>
	</view>
</template>

<script>
	import * as db from '@/common/db.js'
	export default {
		data() {
			return {
				userInfo: this.$db.get('userInfo'),
				list: [],
				datas: {},
				total: 0,
				ids: '',
				totalPage: true
			};
		},
		onReachBottom() {
			this.get_list();
		},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新	
			}, 800);
			this.page = 1;
			this.list = [];
			this.get_list()
		},
		onLoad() {
			
		},
		onShow() {
			this.page = 1;
			this.list = [];
			this.get_list()
		},
		methods: {
			// 选择
			select(id){
				uni.setStorageSync('inv_id',id)
				uni.navigateBack()
			},
			// 申请开票
			submit(){
				if(this.total <= 0 || !this.ids){
					this.$common.errorToShow('请选择开票订单')
					return 
				}
				
				this.$go('/showcase/showcase/openInvoice?id='+this.ids)
			},
			selectItem(item) {
				item.checked = !item.checked
				this.$forceUpdate()
				
				let countPrice = 0
				let ids= []
				this.list.forEach(item => {
					if(item.checked){
						countPrice += Number(item.price)
						ids.push(item.id)
					}
				})
				this.total = countPrice
				this.ids = ids.join(',')
			},
			// 全选
			selectAll() {
				let list = this.list
				for (let i in list) {
					list[i].checked = true
				}

				this.list = list
				this.$forceUpdate()
				console.log('selectAll', list);
				
				let countPrice = 0
				let ids= []
				this.list.forEach(item => {
					if(item.checked){
						countPrice += Number(item.price)
						ids.push(item.id)
					}
				})
				this.total = countPrice
				this.ids = ids.join(',')
			},
			// 多选
			checkboxChange(e) {
				// this.list[e].checked = !this.list[e].checked
			},
			checkboxGroupChange(e) {
				console.log(e);
			},
			get_list() {
				var _this = this;

				this.$api.default.request('invoice/applyInvoiceHisList', {
					page: this.page,
				}).then((res) => {
					if (res.code) {

						if (res.data.data) {
							let list = res.data.data
							list.checked = false
							if (_this.page != 1) {

								_this.list = _this.list.concat(list);

							} else {
								_this.list = list;
							}
							_this.page++; // 页数加一，加载下一页数据
						}
					}
					
					_this.totalPage = false
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}
	
	.fast-box{
		padding: 30rpx;
	}
	
	.fast-item{
		padding: 20rpx;
		background-color: #fff;
		border-radius: 4px;
		font-family: '思源黑体';
		font-size: 14px;
		color: #3D3D3D;
		margin-bottom: 20rpx;
		
		.edit{
			color: #45C4B0;
		}
		
		.desc{
			width: 100%;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			color: #999999;
			margin-top: 10rpx;
		}
	}
	
	.subbox {
		position: fixed;
		bottom: 0;
		left: 0;
		padding-top: 10px;
		padding-bottom: calc(var(--window-bottom) + 10px);
		background-color: #fff;
		display: flex;align-items: center;
		justify-content: center;
		width: 100%;
		
		text{
			width: 630rpx;
			height: 86rpx;
			border-radius: 8px;
			opacity: 1;
			background: #45C4B0;
			text-align: center;
			line-height: 86rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
</style>